<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-DRC-current-waiting-widget" :style="getStyle('area')">
      <div class="dept-area">
        <ScrollX>{{ getRoomDeptInfo }}</ScrollX>
      </div>
      <div class="current-area patient-info">
        <div class="title">正在检查</div>
        <template v-for="(item) in getRoomDoctorInfo('treatingPatient')">
          <div class="content" data-info="item.orderNo">
            {{ item.orderNo || '\u00a0' }} {{ item.patientName || '\u00a0' }}
          </div>
        </template>

      </div>
      <div class="waiting-area patient-info">
        <div class="title">等待检查</div>
        <template v-for="(item) in getRoomDoctorInfo('waitingPatientList')">
          <div class="content" data-info="item.orderNo">
            {{ item.orderNo || '\u00a0' }} {{ item.patientName || '\u00a0' }}
          </div>
        </template>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import {pxToVw} from '@/utils/common';
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue'
import emitter from "@/utils/designer/emitter";
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";

let buildParent = buildParentApi();
export default {
  name: "scene-DRC-current-waiting-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
  },

  data() {
    return {
      optionsInfo: Object(),
      header: require("@a/images/design/header.jpeg"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            return Obj;
        }
      }
    },

    // 获取科室信息
    getRoomDeptInfo() {
      let roomInfo = Object();
      let devType = (this.devType);
      let {roomNameKey, topNameType} = this.optionsInfo;
      let roomDoctorInfo = this.$store.getters['getRoomDeptInfo'];
      if (devType) {
        roomInfo = roomDoctorInfo.apiData;
      } else {
        roomInfo = roomDoctorInfo.mockData;
      }
      if (topNameType === 'roomName') {
        return roomInfo[roomNameKey] || roomInfo['roomName']
      } else {
        return roomInfo[topNameType] || roomInfo['deptName']
      }
    },

    // 获取全量医患信息
    getRoomDoctorInfo() {
      return function (type) {
        let temp = Array();
        let devType = (this.devType);
        let roomDoctorInfo = this.$store.getters['getRoomDoctorInfo'];
        let data;
        if (devType) {
          data = roomDoctorInfo.apiData || Array()
        } else {
          data = roomDoctorInfo.mockData || Array()
        }
        if (data?.length) {
          // 截取第一位医生
          let topPlace = data.slice(0, 1);
          // 获取首位医生的就诊和候诊的患者--数组
          if (!!topPlace && !!(topPlace.length)) {
            if (!!(topPlace[0][type]) && !!(topPlace[0][type].length)) {
              return topPlace[0][type].slice(0, 1);
            } else {
              return [{}]
            }
          } else {
            return [{}]
          }
        } else {
          temp.push({})
          return temp;
        }
      }

    },

  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "roomDeptInfo":
          console.log(`科室信息-${data}`)
          this.states = true;
          // this.parentApi.executeParentMethod('writeLog', JSON.stringify({sign:'模板日志-科室信息',key:key,data:data}));
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign: '模板-科室信息', key: key, data: data}));
          this.$store.dispatch('setRoomDeptInfo', data)
          break
        case "roomDoctorInfo":
          console.log(`医生信息-${data}`);
          this.states = true;
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign: '模板-医生信息', key: key, data: data}));
          // this.parentApi.executeParentMethod('writeLog', JSON.stringify({sign:'模板日志-医生信息',key:key,data:data}));
          this.$store.dispatch('setRoomDoctorInfo', this.$lodash.cloneDeep(data))
          break
      }
    },
  },

  watch: {
    // 获取配置项
    field: {
      handler: function (val) {
        let key = (val.options.config)
        this.optionsInfo = (val.options[key]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-DRC-current-waiting-widget {
  padding: 28px 30px;
  box-sizing: border-box;
  flex: inherit;
  flex-direction: column;
  justify-content: space-between;
  color: #333;
  height: 150px;
  font-size: 40px;
  background: transparent;
  overflow: hidden;

  .dept-area {
    width: 100%;
    height: 488px;
    background: #0059B3;
    border-radius: 20px;
    font-size: 180px;
    color: white;
    line-height: 488px;
    padding: 0 20px;
    box-sizing: border-box;
    overflow: hidden;
    @include fontWeight();

    .scrollText {
      display: flex;
      width: 100%;
      height: 100%;
      align-items: center;
      align-self: center;
      justify-content: left;
    }
  }

  .patient-info {
    overflow: hidden;
    width: 100%;
    margin-top: 40px;
    background: white;
    border-radius: 20px 20px;
    box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
    inset 5px 5px 10px rgba(255, 255, 255, 0.75),
    inset -1px -1px 10px rgba(0, 0, 0, 0.2);

    .title {
      width: 100%;
      height: 206px;
      font-size: 90px;
      color: rgba(0, 89, 179, 1);
      @include fontWeight();
      text-align: center;
      line-height: 206px;
      background: linear-gradient(270deg, #E6ECF0 0%, #FFFFFF 100%);
      border-bottom: 2px solid rgba(0, 0, 0, 0.3);
    }

    .content {
      font-size: 122px;
      color: #333333;
      @include fontWeight();
      display: flex;
      justify-content: center;
      text-align: center;
      align-items: center;
      height: 310px;
      flex-basis: 310px;
      min-height: 310px;
      white-space: nowrap;
    }
  }
}
</style>